/**
 * 保存
 * @param rest
 */
function session(rest) {
    sessionStorage.setItem('token', rest.token);
    sessionStorage.setItem('userId', rest.userId);
    sessionStorage.setItem('userName', rest.userName);
    sessionStorage.setItem('ico', rest.ico);
    sessionStorage.setItem('roles', rest.roles);
    sessionStorage.setItem('menuInfo', rest.menuInfo);
}

/**
 * 清理session 存储登录数据
 */
function clearSession() {
    sessionStorage.removeItem('token');
    sessionStorage.removeItem('userId');
    sessionStorage.removeItem('userName');
    sessionStorage.removeItem('ico');
    sessionStorage.removeItem('roles');
    sessionStorage.removeItem('menuInfo');
}

/**
 * 校验登录状态
 * 如果校验未登录直接跳转到 登录页面
 */
function validLoginStatus() {
   let token = sessionStorage.getItem('token');
   if (!token) {
       clearSession();
   } else {
       window.location.assign('/index.html')
   }
}


function guid1() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        let r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
    });
}

validLoginStatus();
